package protocol;

import net.buffer.ByteBuffer;
import net.protocol.IProtocol;
import net.protocol.Index;

import java.nio.charset.StandardCharsets;

@Index(1)
public class HelloWorld implements IProtocol {

    private String hi;

    public void setHi(String msg)
    {
        hi = msg;
    }

    @Override
    public void deserialize(ByteBuffer buffer) {
        hi = buffer.getString();
    }

    @Override
    public ByteBuffer serialize() {
        byte[] data = hi.getBytes(StandardCharsets.UTF_8);
        return ByteBuffer.from(data);
    }

    @Override
    public int protocolType() {
        return 1;
    }

    @Override
    public String toString() {
        return "hello world : " + hi;
    }
}
